package jplat.core.trans;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
 
/**
 * 
 * @ClassName:  JStringContextUtil   
 * @Description:TODO(获取spring容器，以访问容器中定义的其他bean)   
 * @author:  chenzhuo 
 * @date:   Jan 5, 2019 6:21:18 PM
 */
@Component
public class JSpringContextUtil implements ApplicationContextAware{ 
	
	
	private ApplicationContext applicationContext;

    public Object getBean(String beanName) {
        return applicationContext.getBean(beanName);
    }

    public <T> T getBean(String beanName, Class<T> clazs) {
        return clazs.cast(getBean(beanName));
    }
    @Override
    public void setApplicationContext(ApplicationContext applicationContext)
            throws BeansException {
        this.applicationContext = applicationContext;
    }
}
